home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-05-08 | 4.9 KB | 166 lines | [TEXT/CWIE] |
- // Program Author: Paul Baxter
- // pbaxter@assistivetech.com
- //
- //
-
- #include "aeutils.h"
- #include "aetoken.h"
- #include "aeaccessors.h"
-
-
- // * ****************************************************************************** *
- // * InstallAccessors
- // * Install AppleEvent Accessors
- // * ****************************************************************************** *
- OSErr InstallAccessors(void)
- {
- OSErr err;
-
- err = AEInstallObjectAccessor(cProperty, typeNull, NewOSLAccessorProc(PropertyFromNullAccessor), 0, false);
- err = AEInstallObjectAccessor(cProperty, typeMyApplProp, NewOSLAccessorProc(PropertyFromApplAccessor), 0, false);
- err = AEInstallObjectAccessor(cProperty, typeMyAppl, NewOSLAccessorProc(PropertyFromApplAccessor), 0, false);
- err = AEInstallObjectAccessor(cApplication, typeNull, NewOSLAccessorProc(ApplicationFromNullAccessor), 0, false);
-
- return(err);
- }
-
-
- // * ****************************************************************************** *
- // * ApplicationFromNullAccessor
- // * Get Application Desc from nothing
- // * ****************************************************************************** *
- pascal OSErr ApplicationFromNullAccessor(DescType wantClass,
- const AEDesc *container,
- DescType containerClass,
- DescType form,
- const AEDesc *selectionData,
- AEDesc *value,
- long theRefCon)
- {
- #pragma unused(container,selectionData,theRefCon)
-
- OSErr myErr;
- AppToken theApp;
- AEDesc resultDesc;
-
-
- value->dataHandle = nil;
- resultDesc.dataHandle = nil;
-
-
- if ((wantClass != cApplication) || (containerClass != typeNull) ||
- !((form == formName) || (form == formAbsolutePosition)))
- return(errAEWrongDataType);
-
- if ((form == formName) || (form == formAbsolutePosition)) {
- theApp.highLongOfPSN = 0;
- theApp.lowLongOfPSN = kCurrentProcess;
- }
-
- myErr = AECreateDesc(typeMyAppl, (Ptr)&theApp, sizeof(theApp), value);
-
- return(myErr);
- } /* ApplicationFromNullAccessor */
-
-
-
- // * ****************************************************************************** *
- // * PropertyFromNullAccessor
- // * Get Application Property Desc from nothing
- // * ****************************************************************************** *
- pascal OSErr PropertyFromNullAccessor(DescType wantClass,
- AEDesc *container,
- DescType containerClass,
- DescType form,
- AEDesc *selectionData,
- AEDesc *value,
- long theRefCon)
- {
- #pragma unused (container, containerClass)
-
- AEDesc aDesc = {typeNull, NULL};
- OSErr err;
-
-
- if ((wantClass != cProperty) || (form != formPropertyID))
- return(errAEWrongDataType);
-
- switch (*(DescType *)*selectionData->dataHandle) {
-
- case typeMyApplProp:
- err = PropertyFromApplAccessor(wantClass, &aDesc, typeMyAppl, form,
- selectionData, value, theRefCon);
- break;
-
- default: // Otherwise try an application property - it is from NULL
- err = PropertyFromApplAccessor(wantClass, &aDesc, typeMyAppl, form,
- selectionData, value, theRefCon);
- }
-
- done:
- if (aDesc.dataHandle)
- AEDisposeDesc(&aDesc);
-
- return(err);
- }
-
- // * ****************************************************************************** *
- // * PropertyFromApplAccessor
- // * Get Application Property Desc from nothing
- // * ****************************************************************************** *
-
- pascal OSErr PropertyFromApplAccessor(DescType wantClass,
- const AEDesc *container,
- DescType containerClass,
- DescType form,
- const AEDesc *selectionData,
- AEDesc *value,
- long theRefCon)
- {
- #pragma unused (theRefCon, containerClass)
-
- OSErr myErr;
- OSErr ignoreErr;
- AppToken theApplToken;
- DescType theProperty;
- AEDesc applDesc;
- AEDesc propDesc;
- Size actualSize;
- ApplPropToken myApplProp;
-
- value->dataHandle = nil;
- applDesc.dataHandle = nil;
- propDesc.dataHandle = nil;
-
- if ((wantClass != cProperty) ||
- (form != formPropertyID)) {
- return(errAEWrongDataType);
- }
-
- /* get the application token - it's the container */
-
- myErr = AECoerceDesc(container, typeMyAppl, &applDesc);
- GetRawDataFromDescriptor(&applDesc, (Ptr)&theApplToken, sizeof(theApplToken), &actualSize);
-
- /* get the property - it's in the selection data */
- myErr = AECoerceDesc(selectionData, typeType, &propDesc);
- GetRawDataFromDescriptor(&propDesc, (Ptr)&theProperty, sizeof(theProperty), &actualSize);
- /*
- Combine the two into single token
- */
-
- myApplProp.tokenApplToken = theApplToken;
- myApplProp.tokenApplProperty = theProperty;
-
- myErr = AECreateDesc(typeMyApplProp, (Ptr)&myApplProp, sizeof(myApplProp), value);
-
- if (applDesc.dataHandle)
- ignoreErr = AEDisposeDesc(&applDesc);
-
- if (propDesc.dataHandle)
- ignoreErr = AEDisposeDesc(&propDesc);
-
- return(myErr);
- } // PropertyFromApplAccessor
-
-